/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.typefactory;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

import com.prefabware.commons.QualifiedName;
import com.prefabware.jmodel.JEnumeration;
import com.prefabware.jmodel.JField;
import com.prefabware.jmodel.JModifiers;
import com.prefabware.jmodel.JParameterizedType;
import com.prefabware.jmodel.JType;
import com.prefabware.jmodel.JTypeDeclaration;
import com.prefabware.jmodel.JTypeUtil;
import com.prefabware.jmodel.JVisibility;

public class JEnumerationTypeFactoryDelegee extends JClassTypeFactoryDelegee {
	public  class JEnumerationClassVisitor extends JClassClassVisitor {

		public JEnumerationClassVisitor(TypeFactory typeFactory, JType[] typeArguments) {
			super(typeFactory, typeArguments);
		}

		public JEnumeration getJType() {
			return (JEnumeration) super.getJType();
		}

		@Override
		protected JField newField(Field field, Class<?> clazz, int mod, JModifiers modifiers) {
			if (field.isEnumConstant()) {
				JField jField = JTypeUtil.newJEnumerationConstant(field.getName(),
						getTypeFactory().getJType(field.getType()), modifiers, JVisibility.getVisibility(mod));
				return jField;
			} else {
				return super.newField(field, clazz, mod, modifiers);
			}
		}

		@Override
		protected JType newJType(QualifiedName qualifiedName, JTypeDeclaration declaration, JType... typeArguments) {
			return JEnumerationTypeFactoryDelegee.this.newJType(qualifiedName, declaration, typeArguments);
		}
		
	}

	protected JEnumerationTypeFactoryDelegee() {
		super();
	}

	@SuppressWarnings("unchecked")
	@Override
	public <TYPE extends JType> TYPE newJType(QualifiedName qualifiedName, JTypeDeclaration declaration,
			JType... typeArguments) {
		return (TYPE) new JEnumeration(qualifiedName, declaration);
	}

	@Override
	public boolean acceptType(Class<? extends JType> typeClass, QualifiedName qualifiedName) {
		return typeClass.equals(JEnumeration.class);
	}

	@Override
	public JTypeClassVisitor getVisitor(JType... typeArguments) {
		return new JEnumerationClassVisitor(typeFactory,typeArguments);
	}

}
